package offer.algorithm;

import java.util.Arrays;

/**
 * Description：
 * Author: zhangc
 * Date：2017/7/25 15:51
 */
public class MoreThanHalfNum29 {

    public static int moreThanHalfNum(int[] array) {
        int key = array[ 0 ], time = 1;
        for (int i = 1; i < array.length; i++) {
            if (array[ i ] != key) {
                if (time != 0)
                    time--;
                else {
                    key = array[ i ];
                    time++;
                }
            } else
                time++;
        }
        return key;
    }
}
